<!doctype html>
<html>

	<head>
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="css/header.css" />
	</head>

	<body>

		<header class="mui-bar mui-bar-nav title">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" style="color: white;"></a>
			<a id="link_submit_search" class="mui-icon mui-icon-right-nav mui-pull-right" style="color: white; font-size: 14px;line-height: 25px;">搜索</a>
			<h1 class="mui-title title-color">添加朋友</h1>
		</header>

		<div class="mui-content">
			<div class="mui-input-row">
				<input id="txt_your_friendUsername" type="text" class="mui-input-speech mui-input-clear" style="height: 45px;"
				 placeholder="搜索朋友">
			</div>
		</div>

		<script src="js/mui.js"></script>
		<script src="./js/app.js"></script>
		<script type="text/javascript">
			mui.init();
			mui.plusReady(function() {
				var user = app.getUserGlobalInfo();
				var txt_your_friendUsername = document.getElementById("txt_your_friendUsername");
				txt_your_friendUsername.value = "";
				var link_submit_search = document.getElementById("link_submit_search");
				link_submit_search.addEventListener("tap", function() {
					var friendUsername = txt_your_friendUsername.value;
					if (!app.isNotNull(friendUsername)) {
						app.showToast("用户名不能为空", "error");
						return false;
					}
					plus.nativeUI.showWaiting("请稍等...");
					mui.ajax(app.serverUrl + "/online/users/search?userId=" + user.id + "&friendUsername=" + friendUsername, {
						data: {},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(data) {
							// 关闭等待框
							plus.nativeUI.closeWaiting();
							if (data.code == 20000) {
								mui.openWindow({
									url: "searchFriendsResult.html",
									id: "searchFriendsResult.html",
									styles: {},
									extras: {
										willBeFriend: data.data
									}
								});
							} else {
								app.showToast(data.message, "error");
							}
						}
					});
				})
			})
		</script>
	</body>

</html>
